package com.qr.printlog;

import org.junit.Test;

/**
 * 日志问题
 */
public class DemoLog {

    /**
     * 日志级别，输出日志信息
     * @param level
     * @param message
     */
    public static void showLogger(int level,String message){
        if (level==1){
            System.out.println(message);
        }
    }

    public static void main(String[] args) {
        //空指针异常
        String msg1 = "java.lang.nullpointerexception";
        //找不到指定的类
        String msg2 = "java.lang.classnotfoundexception";
        //算术异常
        String msg3 = "java.lang.arithmeticexception";
        //数组下标越界
        String msg4 = "java.lang.arrayindexoutofboundsexception";
        //方法参数错误
        String msg5 = "java.lang.illegalargumentexception";
        //没有权限异常
        String msg6 = "java.lang.illegalaccessexception";
        //类型不存在异常
        String msg7 = "java.lang.TypeNotPresentException";
        //字符串索引越界
        String msg8 = "java.lang.StringIndexOutOfBoundsException";
        //运行时异常
        String msg9 = "java.lang.RuntimeException";

        /**
         * 用不到得创建，存在性能浪费问题
         */
        showLogger(1,msg1+msg2+msg3+msg4);
        showLogger(2,msg1+msg2+msg3+msg4);

    }

    public static void showLogger2(int level,LogBuilder logBuilder){
        if (level==1){
            logBuilder.builderMessage();
        }
    }

    @Test
    public void printLog(){
        //空指针异常
        String msg1 = "java.lang.nullpointerexception";
        //找不到指定的类
        String msg2 = "java.lang.classnotfoundexception";
        //算术异常
        String msg3 = "java.lang.arithmeticexception";

        /**
         * 真正用到的时候再去创建
         */
        showLogger2(1, new LogBuilder() {
            @Override
            public String builderMessage() {
                return msg1+msg2+msg3;
            }
        });

        showLogger2(2,()-> {
            System.out.println("等级不够");
            return "";
        });
    }

}
